// 巡航器  1
export default {
  methods: {
    driving1(map) {
      this.changeMap([116.379028, 39.865042], 10);
      const that = this;
      that.addCarMarker(map);

      setTimeout(() => {
        AMap.plugin("AMap.Driving", function() {
          var driving = new AMap.Driving({
            // 驾车路线规划策略，AMap.DrivingPolicy.LEAST_TIME是最快捷模式
            map: map,
            panel: "panel",
            extensions: "all"
            // hideMarkers: true
          });
          var startLngLat = [116.379028, 39.865042];
          var endLngLat = [116.427281, 39.903719];

          driving.search(startLngLat, endLngLat, function(status, result) {
            console.log(status, "statusstatus");
            console.log(result, "resultresult");
            // 未出错时，result即是对应的路线规划方案
          });
        });
      }, 2000);
    },
    addCarMarker(map) {
      const position = [116.444134, 39.895144];
      var marker = new AMap.Marker({
        position,
        icon: new AMap.Icon({
          size: new AMap.Size(52, 26), // 图标的大小
          image: "https://webapi.amap.com/images/car.png"
        }),
        offset: new AMap.Pixel(-26, -13),
        angle: -90

      });
      map.add(marker);
    },
    cruise1(map) {
      const that = this;
      AMapUI.load(["ui/misc/PathSimplifier"], function(PathSimplifier) {
        if (!PathSimplifier.supportCanvas) {
          alert("当前环境不支持 Canvas！");
          return;
        }

        var pathSimplifierIns = new PathSimplifier({
          // zIndex: 100,
          map: map, // 所属的地图实例
          getPath: function(pathData, pathIndex) {
            // 返回轨迹数据中的节点坐标信息，[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
            return pathData.path;
          },
          renderOptions: {
            // 轨迹线的样式
            pathLineStyle: {
              // strokeStyle: "red"
              // lineWidth: 6,
              // dirArrowStyle: true
            }
          }
        });

        // 这里构建两条简单的轨迹，仅作示例
        pathSimplifierIns.setData([
          {
            name: "轨迹0",
            path: [
              [100.340417, 27.376994],
              [108.426354, 37.827452]
            ]
          }
          // {
          //   name: "大地线",
          //   path: PathSimplifier.getGeodesicPath([116.405289, 39.904987], [87.61792, 43.793308], 500)
          // }
        ]
        );

        // 创建一个巡航器
        var navg0 = pathSimplifierIns.createPathNavigator(0, // 关联第1条轨迹
          {
            loop: false, // 循环播放
            speed: 1000000
          });
        console.log(that, "that");
        that.navg0test(navg0, 0.4);
        setTimeout(() => {
          console.log(navg0, "navg0");
          pathSimplifierIns.render();
          that.navg0test(navg0, 0.5);
          setTimeout(() => {
            console.log("zhix");
            pathSimplifierIns.render();
            that.navg0test(navg0, 0.6);
          }, 3000);
        }, 1500);
      });
    },
    navg0test(navg, number) {
      navg.start(number);
      navg.pause();
    }
  }

};
